package com.kailu.service.controller;

import java.util.Map;

 


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.kailu.servicelist.form.ServiceList;
import com.kailu.servicelist.service.ServiceListService;
 
@Controller
public class ServiceListController {
 
    @Autowired
    private ServiceListService slService;
 
    @RequestMapping("/index")
    public String listServiceList(Map<String, Object> map) {
 
        map.put("servicelist", new ServiceList());
        map.put("servicelistList", slService.getServiceList());
 
        return "servicelist";
    }
 
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String addContact(@ModelAttribute("servicelist")
    ServiceList serviceList, BindingResult result) {
 
    	slService.addServiceList(serviceList);
 
        return "redirect:/index";
    }
 
    @RequestMapping("/delete/{service_id}")
    public String deleteContact(@PathVariable("service_id")
    Integer service_id) {
    	
    	slService.removeServiceList(service_id);
        return "redirect:/index";
    }
}